package com.itheima.controller;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.common.R;
import com.itheima.dto.DishDto;
import com.itheima.dto.OrdersDto;
import com.itheima.pojo.Dish;
import com.itheima.pojo.Orders;
import com.itheima.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("order")
public class OrdersController {
    @Autowired
    private OrdersService ordersService;

    @PostMapping("/submit")
    public R<String> sumbmit (@RequestBody Orders orders){
        ordersService.submit(orders);
        return R.success("下单成功");
    }

    // 订单明细
    @GetMapping("/page")
    public R<Page<Orders>> pageOrdersDto(@RequestParam Integer page,Integer pageSize,String number,String beginTime,String endTime){

//        Page<OrdersDto> pageInfo = new Page<>(page,pageSize);
        Page<Orders>  OrdersPage = ordersService.pageOrders(page,pageSize,number,beginTime,endTime);

        return  R.success(OrdersPage);
    }

    // 修改派送状态
    @PutMapping
    public R<String> putOrders(@RequestBody Orders orders){
        // updeat Orders set status=? where id=?

        LambdaUpdateWrapper<Orders> lqw = new LambdaUpdateWrapper<>();
        lqw.set(Orders::getStatus,orders.getStatus())
                .eq(Orders::getId,orders.getId());
        ordersService.update(lqw);

        return R.success("修改成功");
    }

    // 查询历史记录 和 最新记录
    @GetMapping("/userPage")
    public R<Page<Orders>> userPage(@RequestParam Integer page,Integer pageSize){
        Page<Orders> ordersPage = new Page<>(page,pageSize);
        //ordersService.page(ordersPage);
        return R.success(ordersService.page(ordersPage));
    }



}

